package com.xxx.Map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/21  15:20
 * @Copyright
 */
public class HashMapDome {
    public static void main(String[] args) {
        HashMap<Student, String> hashMap = new HashMap<>();
        hashMap.put(new Student("张山",22),"jd13");
        hashMap.put(new Student("李四",23),"jd13");
        hashMap.put(new Student("王五",21),"jd13");
        hashMap.put(new Student("赵六",25),"jd13");
        System.out.println(hashMap);
       // set(hashMap);
        Set<Map.Entry<Student, String>> set = hashMap.entrySet();
        Iterator<Map.Entry<Student, String>> iterator = set.iterator();
        while (iterator.hasNext()){
            Map.Entry<Student, String> next = iterator.next();
            Student key = next.getKey();
            String value = next.getValue();
            System.out.println( key+" , "+ value);
        }


    }

    private static void set(HashMap<Student, String> hashMap) {
        Set<Student> set = hashMap.keySet();
        Iterator<Student> iterator = set.iterator();
        while (iterator.hasNext()){
            Student student = iterator.next();
            String s = hashMap.get(student);
            System.out.println(" key:" +student.getName() + "，value:"+student.getAge() );


        }
    }
}
